home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / QD3D to QTVR / ArticleCode / Source / inits.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-20  |  2.9 KB  |  140 lines  |  [TEXT/MPCC]

  1. /*************************************************************************************************
  2.  
  3.  
  4.                         Intialize Machine and all Globals
  5.                         
  6.                         written by Peter Falco, Apple Computer
  7.                         
  8.                         April, 1995
  9.  
  10. *************************************************************************************************/
  11.  
  12. #include <AppleEvents.h>
  13. #include <ToolUtils.h>
  14. #include <Resources.h>
  15. #include "QD3DtoQTVR.h"
  16. #include "extern.h"
  17. #include "inits.h"
  18.  
  19. void InitializeToolbox(void)
  20. {
  21.     short            index ;
  22.     long            gestaltResponse;
  23.     short            numMoreMasters = 20;
  24.         
  25.     InitGraf(&qd.thePort);
  26.     InitFonts();
  27.     InitWindows();
  28.     InitMenus();
  29.     TEInit();
  30.     InitDialogs(0L);
  31.     InitCursor();
  32.     MaxApplZone();
  33.     
  34.     
  35.     SetZone(ApplicZone());
  36.     for( index = 1; index <= numMoreMasters; index++) MoreMasters();
  37.         
  38.     
  39.     FlushEvents(everyEvent, 0);
  40.     
  41.     // Check for Drag and Drop
  42.     if ((Gestalt(gestaltDragMgrAttr, &gestaltResponse) != noErr) ||
  43.             (!(gestaltResponse & (1 << gestaltDragMgrPresent)))) 
  44.         {
  45.         StopAlert(512, 0L);
  46.         ExitToShell();
  47.         }
  48.         
  49.     // Check for QuickDraw 3D
  50.     if ((Gestalt(gestaltQD3D, &gestaltResponse) != noErr) ||
  51.             gestaltResponse == gestaltQD3DNotPresent)
  52.         {
  53.         StopAlert(512, 0L);
  54.         ExitToShell();
  55.         }
  56.  
  57.     // Check for QuickTime
  58.     if (Gestalt(gestaltQuickTime, &gestaltResponse) != noErr)
  59.         {
  60.         StopAlert(512, 0L);
  61.         ExitToShell();
  62.         }
  63. }
  64.  
  65. void InitializeGlobals(void)
  66. {
  67.     gQuit = gQuitting = false;
  68.     
  69.     EnterMovies();
  70.     Q3Initialize();
  71. }
  72.  
  73.  
  74. void DeallocateGlobals(void)
  75. {
  76.     Q3Exit();    
  77.     ExitMovies();
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
  84. void InitAEStuff( void ) 
  85. {
  86.     OSErr  err;
  87.     
  88.     // Set up the self-addressed descriptor record.
  89.     pSelfPSN.highLongOfPSN = 0;
  90.     pSelfPSN.lowLongOfPSN = kCurrentProcess;        // Use this instead of GetCurrentProcess
  91.     err = AECreateDesc(typeProcessSerialNumber,(Ptr)&pSelfPSN,sizeof(ProcessSerialNumber),&pSelfAddress);
  92.     
  93.     pnilDesc.descriptorType = typeNull;            // Initialize the global nil descriptor record.
  94.     pnilDesc.dataHandle = nil;
  95.     
  96.     RegisterMyEvents() ;                            // and finally register appleEvent handlers
  97.     
  98. }
  99.  
  100.  
  101. Boolean SupportsAEVT(void)
  102. {
  103.     OSErr err;
  104.     long response;
  105.     
  106.     if (!myTrapAvailable(kGestaltTrap))
  107.         return false;
  108.     
  109.     err = Gestalt(gestaltAppleEventsAttr,&response);
  110.     if (err!=noErr)
  111.         return false;
  112.         
  113.     return (response && (response << gestaltAppleEventsPresent));
  114. }
  115.  
  116. void RegisterMyEvents(void)
  117. {
  118.     OSErr err;
  119.     
  120.     if (!SupportsAEVT())
  121.         return;
  122.     
  123.     err = AEInstallEventHandler(kCoreEventClass,kAEOpenApplication,NewAEEventHandlerProc(MyAEHandleOAPP),0L,false);
  124.     if (err!=noErr)
  125.         return;
  126.                 
  127.     err = AEInstallEventHandler(kCoreEventClass,kAEOpenDocuments,NewAEEventHandlerProc(MyAEHandleODOC),0L,false);
  128.     if (err!=noErr)
  129.         return;
  130.                 
  131.     err = AEInstallEventHandler(kCoreEventClass,kAEPrintDocuments,NewAEEventHandlerProc(MyAEHandlePDOC),0L,false);
  132.     if (err!=noErr)
  133.         return;
  134.                 
  135.     err = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,NewAEEventHandlerProc(MyAEHandleQUIT),0L,false);
  136.     if (err!=noErr)
  137.         return;            
  138.  
  139.  
  140. }